package com.qin.blog.controller;

import com.qin.blog.domain.TUsers;
import com.qin.blog.dto.UserDto;
import com.qin.blog.service.TUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.qin.blog.commont.CommonResult;

/**
 * @author Leisure
 * create 2022 2022/10/24 19:25
 **/
@Api(tags = "UserController", description = "用户管理")
@Controller
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private TUsersService usersService;

    @ApiOperation(value = "添加用户")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ResponseBody
    public Object insert(@RequestBody UserDto userDto){
        TUsers users = usersService.insertUser(userDto);
        if(users==null){
            return new CommonResult().failed("名字重复,重新设置");
        }
        return users;
    }

    @ApiOperation(value = "通过id查找用户")
    @RequestMapping(value = "/select/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Object select(@PathVariable Long id){
        TUsers users = usersService.selectUser(id);
        if(users==null){
            return new CommonResult().failed("查无此人");
        }
        else {
            return new CommonResult().success(users); 
        }
    }
    
}
